const webpack = require('webpack');
const path = require('path');
let time = new Date().getTime();
module.exports = {
  //路径前缀
  publicPath: '/',
  lintOnSave: true,
  productionSourceMap: false,
  chainWebpack: (config) => {
    //忽略的打包文件
    config.externals({
      vue: 'Vue',
      'vue-router': 'VueRouter',
      vuex: 'Vuex',
      axios: 'axios',
      'element-ui': 'ELEMENT'
    });
    config.resolve.alias.set('vue-demi', 'vue-demi/lib/v2');
    const entry = config.entry('app');
    entry.add('babel-polyfill').end();
    entry.add('classlist-polyfill').end();
    // entry.add('@/mock').end();
  },
  css: {
    extract: { ignoreOrder: true }
  },
  //开发模式反向代理配置，生产模式请使用Nginx部署并配置反向代理
  devServer: {
    port: 4000,
    open: true,
    proxy: {
      '/api': {
        //本地服务接口地址
        target: 'http://192.168.1.186:88',
        // target: process.env.VUE_APP_API_URL,
        //远程演示服务地址,可用于直接启动项目
        //target: 'https://saber.bladex.vip/api',
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/api': '/'
        }
      }
    }
  },
  configureWebpack: {
    plugins:
      process.env.NODE_ENV === 'production'
        ? [
            new webpack.ProvidePlugin({
              $: 'jquery',
              jQuery: 'jquery',
              'windows.jQuery': 'jquery'
            })
          ]
        : [
            new webpack.ProvidePlugin({
              $: 'jquery',
              jQuery: 'jquery',
              'windows.jQuery': 'jquery'
            }),
            new webpack.HotModuleReplacementPlugin() // devServe 自动刷新网页
          ],
    output: {
      filename: `js/[name].${time}.js`,
      chunkFilename: `js/[name].${time}.js`
    }
  }
};
